package com.javatest;

import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * @author LL
 *题目：将一个正整数分解质因数。例如：输入90,打印出90=2*3*3*5。
 * @create 2020-12-10 9:25
 */
public class Subject04 {

    public static void decompose(int num){
        int tmp = num/2;
        for (int i = 2; i <= tmp; i++) {
            if (num%i == 0){
                num = num/i;
                System.out.println("质因数为："+i);
                i = 1;
                continue;
            }
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入一个正整数：");
        try {
            int i = sc.nextInt();
            if(i< 0){
                System.out.println("输入一个正整数");
                return;
            }
            decompose(i);
        }catch (InputMismatchException e){
            System.out.println("输入数字有误"+e);
        }
    }
}
